package dao;

import java.text.SimpleDateFormat;
import java.util.Date;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;

@Entity
@NamedQueries({
	@NamedQuery(name="searchScheduleCode",query=" from Schedule s where s.OID = :code"),
	@NamedQuery(name="searchScheduleDate",query=" from Schedule s where s.dhStart between :dateS and :dateE order by s.dhStart ASC"),
	@NamedQuery(name="searchScheduleDateTime",query=" from Schedule s where s.dhStart = :dateTime and s.OID <> :code")
})
public class Schedule {
	@Id
	@GeneratedValue
	private int OID;
	private String deService;
	 
	private Date dhStart;
	private Date dhEnd;
	
	private String idFit;
	
	@ManyToOne(cascade = {CascadeType.PERSIST,CascadeType.MERGE,CascadeType.REFRESH})
	private Customer customer;
	
	public int getOID() {
		return OID;
	}

	public void setOID(int oID) {
		OID = oID;
	}

	public String getDeService() {
		return deService;
	}

	public void setDeService(String deService) {
		this.deService = deService;
	}

	public Date getDhStart() {
		return dhStart;
	}

	public void setDhStart(Date dhStart) {
		this.dhStart = dhStart;
	}

	public Date getDhEnd() {
		return dhEnd;
	}

	public void setDhEnd(Date dhEnd) {
		this.dhEnd = dhEnd;
	}

	public Customer getCustomer() {
		return customer;
	}

	public void setCustomer(Customer customer) {
		this.customer = customer;
	}
	
	public String getIdFit() {
		return idFit;
	}
	public void setIdFit(String idFit) {
		this.idFit = idFit;
	}
	
	public String getStart(){
		SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
		return sdf.format(dhStart);
	}
	
	public String toString() {
		return getStart() + " - " + getCustomer().getNmCustomer();		
	};
}
